import { Controller, Post, Body, UseGuards } from '@nestjs/common';
import { VerifyCodeService } from './verify-code.service';
import { VerifyCodeDto } from './dto/verifyCode.dto';
import { AuthGuard } from '../../@nt/guards/auth.guard';
import { RestController } from '../../@nt';

// 发送验证码控制器
@Controller('verifyCode')
export class VerifyCodeController extends RestController {
  constructor(protected readonly service: VerifyCodeService) {
    super(service);
  }

  // 发送验证码
  @Post('code')
  @UseGuards(AuthGuard)
  async create(@Body() body: VerifyCodeDto): Promise<any> {
    if (!this.isEmail(body.email)) {
      return this.returnJson(2000, null, '邮箱格式不正确');
    }
    return await this.service.create(body);
  }
}
